interface _CD_ {
    RclassName: RegExp;
}
{
    Object.defineProperty(_CD_.prototype, 'RclassName', {
        writable: false,
        configurable: false,
        enumerable: false,
        value: /^[A-Za-z][0-9A-Za-z\_\-\ ]*$/
    });
}

interface KHTMLElement {
    /**
     * 判断是否有样式类型
     * @param className 样式类型名
     * @returns true: 有指定的样式类型; false: 没有指定的样式类型;
     */
    hasClass(className: string): boolean;
    /**
     * 判断是否有样式类型
     * @param className 样式类型名正则表达式
     * @returns true: 有指定的样式类型; false: 没有指定的样式类型;
     */
    hasClass(className: RegExp): boolean;
}
{
    Object.defineProperty(KHTMLElement.prototype, 'hasClass', {
        writable: false,
        configurable: false,
        enumerable: false,
        value: U.F.overloading('DOM-hasClass',
            {
                types: [Etype.string],
                fn: function (this: KHTMLElement, className: string) {
                    const ele = this.ele();
                    if (!ele) { return false; }
                    className = className.trim();
                    if (U.S.isEmpty(className)) { return false; }
                    if (!U.D.RclassName.test(className)) { return false; }
                    if (className.includes(' ')) {
                        const arr = className.split(' ');
                        for (let i = 0; i < arr.length; i++) {
                            const cls = arr[i];
                            if (U.S.isEmpty(cls)) { continue; }
                            if (!ele.classList.contains(cls)) { return false; }
                        }
                        return true;
                    } else {
                        return ele.classList.contains(className);
                    }
                }
            },
            {
                types: [Etype.RegExp],
                fn: function (this: KHTMLElement, regex: RegExp) {
                    const ele = this.ele();
                    if (!ele) { return false; }
                    for (let i = 0; i < ele.classList.length; i++) {
                        if (regex.test(ele.classList[i])) { return true; }
                    }
                    return false;
                }
            },
        )
    });
}
